package cc.mcggdd.leah.boot.stock.controller;

import cc.mcggdd.leah.boot.stock.service.StockInitCapitalService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cc.mcggdd.leah.boot.stock.model.form.StockInitCapitalForm;
import cc.mcggdd.leah.boot.stock.model.query.StockInitCapitalQuery;
import cc.mcggdd.leah.boot.stock.model.vo.StockInitCapitalVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import cc.mcggdd.leah.boot.common.result.PageResult;
import cc.mcggdd.leah.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 初始资金前端控制层
 *
 * @author 
 * @since 2025-02-08 10:16
 */
@Tag(name = "初始资金接口")
@RestController
@RequestMapping("/api/v1/stockInitCapitals")
@RequiredArgsConstructor
public class StockInitCapitalController  {

    private final StockInitCapitalService stockInitCapitalService;

    @Operation(summary = "初始资金分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('stock:stockInitCapital:query')")
    public PageResult<StockInitCapitalVO> getStockInitCapitalPage(StockInitCapitalQuery queryParams ) {
        IPage<StockInitCapitalVO> result = stockInitCapitalService.getStockInitCapitalPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增初始资金")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('stock:stockInitCapital:add')")
    public Result<Void> saveStockInitCapital(@RequestBody @Valid StockInitCapitalForm formData ) {
        boolean result = stockInitCapitalService.saveStockInitCapital(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取初始资金表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('stock:stockInitCapital:edit')")
    public Result<StockInitCapitalForm> getStockInitCapitalForm(
        @Parameter(description = "初始资金ID") @PathVariable Long id
    ) {
        StockInitCapitalForm formData = stockInitCapitalService.getStockInitCapitalFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改初始资金")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('stock:stockInitCapital:edit')")
    public Result<Void> updateStockInitCapital(
            @Parameter(description = "初始资金ID") @PathVariable Long id,
            @RequestBody @Validated StockInitCapitalForm formData
    ) {
        boolean result = stockInitCapitalService.updateStockInitCapital(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除初始资金")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('stock:stockInitCapital:delete')")
    public Result<Void> deleteStockInitCapitals(
        @Parameter(description = "初始资金ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = stockInitCapitalService.deleteStockInitCapitals(ids);
        return Result.judge(result);
    }
}
